package com.example.demo.mapper;

import com.example.demo.model.PersonalityType;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PersonalityTypeMapper {
    
    @Select("SELECT null as id, type_code as code, name, overview as description, leadership_style as leadershipStyle, " +
           "learning_style as learningStyle, problem_solving as problemSolvingStyle, work_preference as workEnvironment, " +
           "weaknesses as potentialWeaknesses, development as developmentSuggestions, '' as suitableFields, '' as suitableCareers " +
           "FROM personality_templates WHERE type_code = #{id}")
    PersonalityType findById(Integer id);
    
    @Select("SELECT null as id, type_code as code, name, overview as description, leadership_style as leadershipStyle, " +
           "learning_style as learningStyle, problem_solving as problemSolvingStyle, work_preference as workEnvironment, " +
           "weaknesses as potentialWeaknesses, development as developmentSuggestions, '' as suitableFields, '' as suitableCareers " +
           "FROM personality_templates WHERE type_code = #{code}")
    PersonalityType findByCode(String code);
    
    @Select("SELECT null as id, type_code as code, name, overview as description, leadership_style as leadershipStyle, " +
           "learning_style as learningStyle, problem_solving as problemSolvingStyle, work_preference as workEnvironment, " +
           "weaknesses as potentialWeaknesses, development as developmentSuggestions, '' as suitableFields, '' as suitableCareers " +
           "FROM personality_templates")
    List<PersonalityType> findAll();
    
    @Insert("INSERT INTO personality_templates (type_code, name, overview, leadership_style, " +
            "learning_style, problem_solving, work_preference, weaknesses, development, trait_order) " +
            "VALUES (#{code}, #{name}, #{description}, #{leadershipStyle}, " +
            "#{learningStyle}, #{problemSolvingStyle}, #{workEnvironment}, #{potentialWeaknesses}, " +
            "#{developmentSuggestions}, '')")
    void insert(PersonalityType personalityType);
    
    @Update("UPDATE personality_templates SET name = #{name}, overview = #{description}, " +
            "leadership_style = #{leadershipStyle}, learning_style = #{learningStyle}, " +
            "problem_solving = #{problemSolvingStyle}, work_preference = #{workEnvironment}, " +
            "weaknesses = #{potentialWeaknesses}, development = #{developmentSuggestions} " +
            "WHERE type_code = #{code}")
    void update(PersonalityType personalityType);
    
    @Delete("DELETE FROM personality_templates WHERE type_code = #{code}")
    void deleteById(Integer id);
} 